package EMS::Mailguard::MailguardRetrieveMembers;


# Depends on Mail::Internet
use EMS::Mailguard::Mailguardout;
use Data::Dumper;
use XML::Simple;

sub new{
  my $class = shift();
  my $self =  bless ({}, $class);

  my %required_arguments = (
        'mode' => 'branch',
        'list' => undef,
        _log_ref => undef,
        @_);

 # Make sure that the required constructor arguments are there.
  for ( keys %required_arguments ){
     $self->{_log_object}->Death(682, "Required constructor <$_> 
     argument missing in MailguardSession.pm")
       unless ( defined ($required_arguments{$_}) );
     $self->{$_}=$required_arguments{$_};
  }

  return $self;
}

sub members{
  my $self=shift();

  return [keys ( %{+ $self->{'list'}->{'MEMBERS'} } ) ] 
    if ($self->{'mode'} eq 'branch');

  # STUB FOR DIRECT LDAP INTERGRATION
  # I'm thinking this should be a required argument passed
  # into the constructor, as well as a required DN root for the lookup.
  #
  # Nevertheless, you could use the loaddb that's based around LDAP to
  # write the same cached DB and then you could use the basic branch setup,
  # but if you really need that LIVE quality then you should fill this method
  # out.

  if ( $self->{'mode'} eq 'ldap' ){
    $self->{_log_object}->Death(784, "Unimplemented mode called.  Please see
    MailguardRetrieveMembers.pm code");
  }

}

######################################################################
# POD Documentation
######################################################################

=pod

=head1 

EMS::Mailguard::MailguardRetrieveMembers

=head2 

Synopsis

A module for retrieving the members for a list.  While it is currently coded
only to look at the local cachDB, extensions for live lookup via LDAP can be
placed here.

=head2 Constructor ( All Paramters Listed are B<REQUIRED> )

=over 4

=item *

B<list>:  SCALAR: Name of the list that's being operated upon

=item *

B<_log_ref>:  EMS::LogIt Object:  Object for logging to a file

=back

=head 3 Optional Argument

=over 4

=item *

B<mode>:  The default mode is to look at the branch passed in in the
constructor.  This could be changed to 'ldap' provided the ldap stubs were
filled out and the ancillary LDAP objects were passed in.  The default value
is 'branch'.

=back

=head 2

Public Methods

=over 4

=item * members()

Returns an array reference with the members as extracted from the cacheDB
branch.  You may want to use the lookup_in_loaddb.pl to understand what a
branch looks like e.g. I<lookup_in_loaddb.pl mailguard-sample>

=head2 AUTHOR

Steven G. Harms (stharms@cisco.com)

=cut

return 1;
